﻿namespace Dotnet.Utils.Utility.Other
{
    public class Utility
    {
        /// <summary>
        /// 声明一个已经是否声明自身类的对象
        /// </summary>
        private static volatile Utility _instance = null;

        /// <summary>
        /// 锁
        /// </summary>
        private static readonly object lockHelper = new object();

        /// <summary>
        /// 创建单实例（函数方式） 双重锁
        /// </summary>
        /// <returns></returns>
        public static Utility CreateInstance()
        {
            if (_instance == null)
                lock (lockHelper)
                    _instance ??= new Utility();

            //if (_instance == null)
            //{
            //    lock (lockHelper)
            //    {
            //        if (_instance == null)
            //            _instance = new Utility();
            //    }
            //}

            return _instance;
        }
    }

    public class CommonInstance
    {
        private static CommonInstance instance;

        public static CommonInstance Instance
        {
            get
            {
                if (instance == null)
                {
                    instance = new CommonInstance();
                }
                return instance;
            }
        }

        public CommonInstance()
        {
        }

        static CommonInstance()
        {
        }
    }
}